﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Globalization;

namespace Microsoft.Office.OneNote
{
    [OneNoteXmlElement("Size")]
    public sealed class OneNoteOutlineSize :  OneNoteObject, IEquatable<OneNoteOutlineSize>
    {
        internal static readonly OneNoteProperty WidthProperty = RegisterProperty("width");
        internal static readonly OneNoteProperty HeightProperty = RegisterProperty("height");

        private static OneNoteProperty RegisterProperty(string name)
        {
            return OneNoteProperty.Register(name, typeof(Double), typeof(OneNoteOutlineSize));
        }

        internal OneNoteOutlineSize()
        {
        }

        public OneNoteOutlineSize(double width, double height)
        {
            SetValue(WidthProperty, width);
            SetValue(HeightProperty, height);
        }

        public double Width
        {
            get { return GetValue<Double>(WidthProperty); }
        }

        public double Height
        {
            get { return GetValue<Double>(HeightProperty); }
        }

        public override bool Equals(object obj)
        {
            return this.EqualsHelper(obj);
        }

        public bool Equals(OneNoteOutlineSize other)
        {
            if (ReferenceEquals(other, null))
            {
                return false;
            }

            return
                DoubleHelper.AreClose(Width, other.Width) &&
                DoubleHelper.AreClose(Height, other.Height);
        }

        public override int GetHashCode()
        {
            return Width.GetHashCode() ^ Height.GetHashCode();
        }

        public override string ToString()
        {
            return string.Format(
                CultureInfo.InvariantCulture,
                "Width={0}, Height={1}", Width, Height);
        }
    }
}
